package cn.bisoft.java.core;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Spring
{
	private static String SPRITN_CONF_FILE = "system-component-definition.xml";

	private transient static Boolean isRun = false;

	private static ApplicationContext applicationContext = null;
	
	public synchronized static ApplicationContext loadApplicationContext()
	{
		if (!isRun.booleanValue())
		{
			isRun = Boolean.valueOf(true);

			applicationContext = new ClassPathXmlApplicationContext(SPRITN_CONF_FILE);
		}

		return applicationContext;
	}

	public static ApplicationContext getApplicationContext()
	{
		synchronized (Spring.class)
		{
			if (null == applicationContext)
			{
				loadApplicationContext();
			}
			return applicationContext;
		}
	}
	
	public static Object getBean(String id)
	{
		if (!isRun.booleanValue())
		{
			loadApplicationContext();
		}
		
		return applicationContext.getBean(id);
	}
}
